package com.fac.controller.admin;

import com.fac.dto.EquipmentCreateDTO;
import com.fac.dto.EquipmentPageQueryDTO;
import com.fac.dto.EquipmentUpdateDTO;
import com.fac.result.PageResult;
import com.fac.result.Result;
import com.fac.service.EquipmentService;
import com.fac.vo.EquipmentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * 设备管理控制器
 */
@RestController
@RequestMapping("/admin/equipment")
@Api(tags = "管理端-设备管理相关接口")
@Slf4j
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;

    /**
     * 创建设备
     *
     * @param equipmentCreateDTO 设备创建DTO
     * @return 创建结果
     */
    @PostMapping
    @ApiOperation("创建设备")
    @ResponseStatus(HttpStatus.CREATED)
    public Result<EquipmentVO> create(@RequestBody EquipmentCreateDTO equipmentCreateDTO) {
        log.info("创建设备：{}", equipmentCreateDTO);
        EquipmentVO equipmentVO = equipmentService.create(equipmentCreateDTO);
        return Result.success(equipmentVO);
    }

    /**
     * 分页查询设备
     *
     * @param equipmentPageQueryDTO 分页查询条件
     * @return 分页结果
     */
    @GetMapping
    @ApiOperation("分页查询设备")
    public Result<PageResult> page(EquipmentPageQueryDTO equipmentPageQueryDTO) {
        log.info("分页查询设备：{}", equipmentPageQueryDTO);
        PageResult pageResult = equipmentService.pageQuery(equipmentPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 更新设备
     *
     * @param equipmentId 设备ID
     * @param equipmentUpdateDTO 设备更新DTO
     * @return 更新结果
     */
    @PutMapping("/{equipmentId}")
    @ApiOperation("更新设备")
    public Result<EquipmentVO> update(@PathVariable Long equipmentId, @RequestBody EquipmentUpdateDTO equipmentUpdateDTO) {
        log.info("更新设备，ID：{}，更新内容：{}", equipmentId, equipmentUpdateDTO);
        EquipmentVO equipmentVO = equipmentService.update(equipmentId, equipmentUpdateDTO);
        return Result.success(equipmentVO);
    }
}
